package com.xianshijian.oauth.common.utils;

import java.util.Random;

public class RandomUtil {
	/**
	 * 随机数种子
	 */
	private static char[] numbersAndLetters = ("0123456789abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ").toCharArray();
	
	/**
	 * 验证码
	 * */
	private static char[] identifyingCode=("0123456789").toCharArray();
	
	
	/**
	 * @Description:生成16位随机数
	 * @return randBuffer
	 */
	public static String random(int len){
		Random random = new Random();
		char[] randBuffer = new char[len];
		for (int i = 0; i < randBuffer.length; i++) {
			randBuffer[i] = numbersAndLetters[random.nextInt(len)];
		}
		return new String(randBuffer);
	}
	
	
	/**
	 * 获取6位验证码
	 * */
	public static String identifyingCodeRandom(){
		Random random = new Random();
		char[] randBuffer = new char[6];
		for (int i = 0; i < randBuffer.length; i++) {
			randBuffer[i] = identifyingCode[random.nextInt(6)];
		}
		return new String(randBuffer);
	}
	
	
	/**
	 * 获取账户随机密码
	 */
	public static String getRandomPwd(int len){
		String base = "abcdefghijklmnopqrstuvwxyz0123456789";     
	    Random random = new Random();     
	    StringBuffer sb = new StringBuffer();     
	    for (int i = 0; i < len; i++) {     
	        int number = random.nextInt(base.length());     
	        sb.append(base.charAt(number));     
	    }     
	    return sb.toString(); 
	}		
	


}
